package com.whc;

/**
 * Created by Administrator on 2022/2/10.
 */
public class PrintAB  implements Runnable{

    private static Object object = new Object();
    private int total = 100;
    private static int curNum = 1;

    private int flag;
    private String printStr;

    public PrintAB(int flag, String printStr) {
        this.flag = flag;
        this.printStr = printStr;
    }

    public void run() {
        synchronized (object) {
            while (curNum < total) {
                if (curNum % 2 != flag) {
                    try {
                        object.wait();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                System.out.println("========" + printStr + "=======" + curNum);
                curNum++;
                object.notifyAll();
            }
        }
    }
}
